﻿Imports ComponentFactory.Krypton.Toolkit

Public Class Backup
    Inherits KryptonForm

    Private modo As String

    Sub New(ByVal modo As String)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.

        Me.modo = modo

        Select Case modo

            Case "restaurar"
                gbSalvar.Enabled = False
        End Select
    End Sub

    Private Sub btnDiretorioSalvar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDiretorioSalvar.Click
        OleDb.OleDbConnection.ReleaseObjectPool()

        If (pastaDlg.ShowDialog() = Windows.Forms.DialogResult.Cancel) Then
            txtSalvar.Text = Nothing
            btnSalvar.Enabled = False
        Else
            txtSalvar.Text = pastaDlg.SelectedPath
            btnSalvar.Enabled = True
        End If

    End Sub

    Private Sub btnSalvar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalvar.Click
        If Not (pastaDlg.SelectedPath.Chars(pastaDlg.SelectedPath.Length - 1).Equals("\")) Then
            IO.File.Copy(Config.DiretorioBD, pastaDlg.SelectedPath & "\BDFarense.WSB", True)
            If (KryptonMessageBox.Show("Backup efetuado com sucesso. Deseja abrir a pasta de destino?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                Process.Start("explorer.exe", pastaDlg.SelectedPath)
            End If
            txtSalvar.Text = Nothing
            btnSalvar.Enabled = False
        End If

    End Sub

    Private Sub btnDiretorioRestaurar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDiretorioRestaurar.Click
        If (openDlg.ShowDialog() = Windows.Forms.DialogResult.Cancel) Then
            txtRestaurar.Text = Nothing
            btnRestaurar.Enabled = False
        Else
            txtRestaurar.Text = openDlg.FileName
            btnRestaurar.Enabled = True
        End If

    End Sub

    Private Sub btnRestaurar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestaurar.Click
        OleDb.OleDbConnection.ReleaseObjectPool()

        IO.File.Copy(openDlg.FileName, Config.DiretorioBD, True)
        KryptonMessageBox.Show("Restauração efetuada com sucesso!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
        txtRestaurar.Text = Nothing
        btnRestaurar.Enabled = False

        If (Me.modo.Equals("restaurar")) Then
            Me.DialogResult = Windows.Forms.DialogResult.Yes
        End If
    End Sub

    Private Sub btnFechar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFechar.Click
        Me.Dispose()
    End Sub

    Private Sub gbSalvar_Panel_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles gbSalvar.Panel.DragDrop

    End Sub
End Class